package com.bgs.service.impl;

import com.bgs.mapper.UserMapper;
import com.bgs.pojo.Achievement;
import com.bgs.pojo.AddStore;
import com.bgs.pojo.User;
import com.bgs.pojo.UserFind;
import com.bgs.service.UserService;
import com.bgs.utils.OrderUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @program: xkgc
 * @description:
 * @author: Mr.Zhao
 * @create: 2022-05-13 14:15
 */
@Service
public class UserServiceImpl implements UserService {


    @Autowired
    private UserMapper userMapper;

    @Override
    public List<UserFind> findAllUser(String userName, String phone,Integer storeId) {
        return userMapper.findAllUser(userName,phone,storeId);
    }

    @Override
    public int updatedUser(User user) {
        LocalDateTime localDateTime = LocalDateTime.now();
        user.setUpdateTime(localDateTime);

        return userMapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public int addUser(User user) {

        user.setUserNumber(OrderUtils.getOrderCode(1));
        LocalDateTime localDateTime = LocalDateTime.now();
        user.setCreationTime(localDateTime);
        user.setUpdateTime(localDateTime);
        user.setIsDel("n");
        user.setStoreId(user.getStoreId());
        return userMapper.insertSelective(user);
    }

    @Override
    public int useCount(Integer storeId) {
        return userMapper.useCount(storeId);
    }

    @Override
    public List<Achievement> findAllAchieve(Integer userId) {
        return userMapper.findAllAchieve(userId);
    }

    @Override
    public int addStore(AddStore addStore) {
        System.out.println();
        LocalDateTime localDateTime = LocalDateTime.now();
        addStore.setUpdateTime(localDateTime);

        return userMapper.addStore(addStore);
    }
}
